<?php

/*
 * This class is used for as Model for Product table 
 */

class Model_Userjob extends Model_Base {

    protected $_name = 'tbl_user_job';
    protected $_primaryKey = 'usr_ref_id';

    /**
     * Fetch an individual entry
     *
     * @param  int|string $id
     * @return null|Zend_Db_Table_Row_Abstract
     */
    public function fetchEntryById($id) {
        $select = $this->select()
                ->from(array('job' => 'tbl_user_job'))
                ->where('usr_ref_id = ?', $id);
        // see reasoning in fetchEntries() as to why we return only an array
        $data = $this->fetchRow($select);
        if (!empty($data)) {
            return $data->toArray();
        } else {
            return array();
        }
    }

    /**
     *  This function is used to get Jobs
     * @return null|Zend_Db_Table_Row_Abstract
     */
    public function fetchJobs($where = "", $limit = "", $offset = "0", $order = 'usr_ref_id', $sort = 'ASC') {
        $select = $this->select()
                ->from(array('job' => 'tbl_user_job'));
        if ($where != '') {
            $select->where($where);
        }
        if ($limit != "") {
            $select->limit($limit, $offset);
        }

        $select->order($order . " " . $sort);
        #echo $select; exit;
        $data = parent::fetchAll($select);
        if (!empty($data)) {
            return $data->toArray();
        } else {
            return array();
        }
    }

    /**
     *  This function is used to get total orders
     * @return int
     */
    public function getJobCount($where) {
        $select = $this->select()
                ->from(array('jobs' => 'tbl_user_job'), Array('cnt' => 'count(*)'));
        if ($where != '') {
            $select->where($where);
        }
        $rows = parent::fetchRow($select);
        return($rows->cnt);
    }

    //getjobarray
    public function getjobArray($where = '') {
        $jobArray = $this->fetchJobs($where);
        foreach ($jobArray as $com) {
            $finalArray[$com['usr_ref_id']] = $com['job_name'];
        }
        if (!empty($finalArray)) {
            return $finalArray;
        } else {
            return array();
        }
    }
    
    
    /**
     *  This function is used to delete Jobs
     * @return null|Zend_Db_Table_Row_Abstract
     */
    public function deleteJob($usr_ref_id) {
        $this->delete('usr_ref_id = ' . (int) $usr_ref_id);
    }

}
